package com.client.ryt.activity;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.client.ryt.R;
import com.client.ryt.adapter.StatementAdapter;
import com.client.ryt.basic.BaseActivity;
import com.client.ryt.basic.BaseException;
import com.client.ryt.basic.BaseLiteners;
import com.client.ryt.basic.BaseParameters;
import com.client.ryt.basic.BaseResponse;
import com.client.ryt.basic.BaseTask;
import com.client.ryt.config.LoginConfig;
import com.client.ryt.entity.biz.StatementEntity;
import com.client.ryt.entity.parameter.StatementConfirmParamters;
import com.client.ryt.task.http.request.StatementConfirmRequest;
import com.client.ryt.task.http.request.StatementRequest;
import com.client.ryt.task.http.response.StatementResponse;

import java.util.ArrayList;
import java.util.List;

/*****
 * 对账清单
 */
public class StatementActivity extends BaseActivity{

    StatementActivity oThis = this;
    ListView listView;
    StatementAdapter statementAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statement);
        listView = (ListView)findViewById(R.id.listview);
        loadData();
    }

    private void loadData(){
        BaseParameters baseParameters = new BaseParameters();
        baseParameters.setToken(LoginConfig.getLoginConfig().getToken());
        baseParameters.setUsername(LoginConfig.getLoginConfig().getShopMember().getUsername());
        baseParameters.setShopid(LoginConfig.getLoginConfig().getShopMember().getShop_id());
        new BaseTask<StatementRequest,StatementResponse>(this,StatementRequest.class,StatementResponse.class,baseParameters,new BaseLiteners.BaseResponseListener() {
            @Override
            public void OnFail(BaseException e) {
                showToast(e.getErrmsg());
            }

            @Override
            public void OnSuccess(BaseResponse o) {
                StatementResponse statementResponse = (StatementResponse)o;
                if(((StatementResponse) o).getList().size()>0) {
                    statementAdapter = new StatementAdapter(StatementActivity.this, statementResponse.getList());
                    listView.setAdapter(statementAdapter);
                    ((LinearLayout)findViewById(R.id.ll_nodata)).setVisibility(View.GONE);
                }else{
                    ((LinearLayout)findViewById(R.id.ll_nodata)).setVisibility(View.VISIBLE);
                }
            }
        },true).execute();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.statement, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
